//
//  UnsafeRawPointer+HEX.swift
//  ITShared
//
//  Created by ellzu gu on 2021/7/9.
//

import Foundation

extension UnsafeRawPointer: ExtensionCompatible{}

public extension Extension where Base == UnsafeRawPointer {
    
    func hexString(rawLen: Int) -> String {
        return Self.hexString(base, rawLen: rawLen)
    }
    
    static func hexString(_ raw: UnsafeRawPointer, rawLen: Int) -> String {
        var str = String()
        for i in 0..<rawLen {
            let curValue: UInt8 = raw.load(fromByteOffset: i, as: UInt8.self)
            str.append(String(format: "%0x", curValue))
        }
        return str
    }
    
}
